

#ifndef UI_WIDGETS_H__
#define UI_WIDGETS_H__

#include <stdint.h>

#ifndef ARRAY_NUM
#define ARRAY_NUM(x)    ( sizeof( x )/sizeof( x[0] ) )
#endif 

typedef enum{
    UI_WIDGET_TYPE_BASE = 0,
    
    UI_WIDGET_TYPE_ANIMATE,
    UI_WIDGET_TYPE_CANVAS ,
    UI_WIDGET_TYPE_CIRCLEBAR, 
    UI_WIDGET_TYPE_COLORREPLACER,
    UI_WIDGET_TYPE_CONTAINER, 
    
    UI_WIDGET_TYPE_DIGITAL,
    UI_WIDGET_TYPE_DIGITALLIST,
    UI_WIDGET_TYPE_LABEL,    
    UI_WIDGET_TYPE_NUMBER, 
    UI_WIDGET_TYPE_NUMBERLIST,
    
    UI_WIDGET_TYPE_PANEL, 
    UI_WIDGET_TYPE_PICKER, 
    UI_WIDGET_TYPE_PICTUREBOX,
    UI_WIDGET_TYPE_POINTER,
    UI_WIDGET_TYPE_QRCODE, 

    UI_WIDGET_TYPE_PROGRESSBAR,     
    UI_WIDGET_TYPE_SWITCH, 
    UI_WIDGET_TYPE_TEXTBOX,        
    UI_WIDGET_TYPE_TEXTPAGE,  
    UI_WIDGET_TYPE_TOUCH,    
}iqw_ui_widget_type_t;

#if defined (__CC_ARM)
  #pragma push
  #pragma anon_unions
#endif 

typedef void* (*get_text_func_t)(int i );

typedef union 
{
    struct 
    {
        int16_t x;
        int16_t y;
        int16_t idx;
    }animation;
    struct 
    {
        uint16_t idx; // just update idx 
    }image;

    struct
    {
        void*   context;
        uint16_t len;
    }text;

    struct 
    {
        int16_t idx;
    }digital;

    struct 
    {
        uint32_t  value; 
    }digitallist;

    struct
    {
        void* context;
        uint16_t len;
        uint32_t value;
    }number;

    struct 
    {
        uint32_t value[4];
        uint8_t cnt; 
    }numberlist;

    struct 
    {
        void*  (*get_text)(int i);
        uint16_t count; // 个数

        int16_t delta_y; 
    }picker;

    struct 
    {
        uint16_t angle; 
    }pointer;

    struct 
    {
        uint16_t onoff; 
    }xswitch;

    struct 
    {
        void*   content;
        uint16_t len;
        int16_t roll_delta_y; 
    }textpage;

    struct 
    {
        uint16_t angles;
        uint16_t anglee;
    }circlebar;

    struct 
    {
        uint16_t percent; 
    }progressbar;

    struct
    {
        uint8_t*    matrix;
    }qrcode;
}ui_property_t;


typedef struct 
{
    int16_t     x;
    int16_t     y;
    void*       text;
    uint16_t    length; 
}ui_picker_data_t;

typedef struct
{
    union 
    {
        // numberlist 
        struct 
        {
            uint32_t idx[4]; 
        }digitiallist;


        // 指针额外属性，用于重建指针的显示区域
        struct
        {
            int16_t xmin;
            int16_t ymin;
            int16_t xmax;
            int16_t ymax;
            
        }pointer;

        // 文本额外属性，用于更新文本位置
        struct 
        {
            int16_t nx;
            int16_t ny;

            int16_t active_rs;
            int16_t active_re;

            int16_t delta_y;
            int16_t delta_max;

            int16_t height;         
            uint8_t updateheight;   
        }text; 

        struct
        {
            ui_picker_data_t*   pts; // 三个位置数据点

            uint16_t count; // item counts 
            int16_t index; // item selected index 

            uint16_t height; 
            int16_t  delta; 
        }picker;

        struct 
        {
            int16_t xs;
            int16_t xe;
            int16_t ys;
            int16_t ye;
        }progressbar;

        struct 
        {
            int16_t nx;
            int16_t ny;
            uint16_t scale; 
            uint16_t size;
        }qrcode;
    };
}ui_ext_property_t;

/*
1。 当控件需要修改“值”属性时，需要指定控件的数据来源（考虑后续自定义表盘时，程序要根据数据来源更新值）
    不需要数据来源的，比如背景及背景图片、图标等
    其余均需要数据来源
    更新值属性由界面进行更新
*/

typedef struct 
{
    // base property 
    uint16_t type;

    // x,y,w,h必须指定，这可以让GUI快速判断当前控件是否需要绘制
    int16_t x;
    int16_t y;
    int16_t w;
    int16_t h;

    uint16_t tag:     8; // tag，用来区别控件触摸事件
    uint16_t visible: 1; // 0表示控件不可见，1表示可见
    uint16_t border:  1; // 是否绘制边框，目前仅支持progressbar 
    uint16_t touchable:   1; // 当允许触摸时，同一组控件需要定义不同的tag，用来区分哪个触摸生效的对象
    uint16_t overlay:     1; // 使用图片控件时，此属性为0，图片将覆盖； 1表示叠加（叠加时需要指定透明颜色 ）
    // 12byte to here 

    // extension property
    union 
    {
        // 动画
        struct
        {
            uint16_t imagelist;     // 图像列表
            uint16_t idx;           // 当前使用的图像索引
            uint16_t maskcolor;     // overlay = 1, specify mask color that will be ignored by GUI

            uint16_t counts;        // 图像数            
            uint16_t datasource;    // 数据来源
        }uiAnimation;

        // 画布
        struct
        {
            uint16_t color;
        }uiCanvas;

        // 环形进度条
        struct 
        {
            uint16_t color;
            uint16_t radius;
            uint16_t thickness;
            uint16_t angles;    // 开始角度
            uint16_t anglee;    // 结束角度
            uint16_t datasource; // 数据来源
        }uiCirclebar;

        // 颜色替换器
        struct 
        {
            uint16_t srcColor;
            uint16_t dstColor;
        }uiColorReplacer;

        // 控件容器
        struct 
        {
            uint16_t sub_widget_cnt; // 包含的子控件个数
            int16_t  delta_x;
            int16_t  delta_y;
        }uiContainer;

        // 数字图片控件(单个)
        struct 
        {
            uint16_t imagelist; // 
            uint16_t index; 
            uint16_t maskcolor; //
   
            uint16_t datasource; 
        }uiDigital;

        // 数据图片控件（多个）（比如计步显示使用图片文字时，使用此控件） 
        struct
        {
            uint16_t imagelist; 
            uint16_t index;       //not used, but align to others control 
            uint16_t maskcolor;

            uint8_t  idx[6]; // 最大5个，坐标平移绘制
            uint8_t  cnt;  // 
            
            uint16_t datasource;
            char*    format;
        }uiDigitallist;

        // 标签控件
        struct 
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension; 

            uint16_t datasource; 
        }uiLabel;

        // 遮罩控件,此控件旋转最顶层
        struct 
        {
            uint16_t maskcolor; // 需要遮罩的颜色 
            uint16_t color;     // 替换的颜色 
        }uiMaskColor;

        struct 
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;

            char*   format;             
        }uiNumber;

        struct 
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;

            char* format; 
        }uiNumberlist;

        // 图片控件（TODO:动画控件与此合并）
        struct 
        {
            uint16_t imagelist;
            uint16_t idx; 
            uint16_t maskcolor;
        }uiPicturebox;

        // 滚动选择器控件（使用字符串数组，这样可以支持除数字外的字符,缺点是需要定义这么多的字符数组） 
        struct
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;
            uint16_t pitch;                 
        }uiPicker;

        // 旋转指针
        struct 
        {
            uint16_t imagelist;
            uint16_t idx; 
            uint16_t maskcolor; 

            int16_t pivot_x;
            int16_t pivot_y;
            int16_t angle; // 当前角度
            
            // 扩展属性
            ui_ext_property_t *extension; 
        }uiPointer;

        struct 
        {
            uint16_t backcolor;
            uint16_t forecolor; 
            uint16_t value;         // 当前值 

            ui_ext_property_t* extension;
        }uiProgressbar;

        struct 
        {
            uint16_t backcolor;
            uint16_t forecolor;

            uint8_t* matrix;        // qrcode点阵
            uint16_t datasource; 

            ui_ext_property_t* extension;
        }uiQrcode;

        struct 
        {
            uint16_t imagelist;
            uint16_t idx;
            uint16_t maskcolor;

            uint16_t idxon;
            uint16_t idxoff;
            

            uint16_t datasource; 
        }uiSwitch;

        struct 
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;
            

        }uiTextbox;

        struct 
        {            
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;            
        }uiTextpage;

#if 1 
        // Text文本控件字符串位置
        struct
        {
            void* content;
            uint16_t len;
            uint16_t maxlen;

            uint16_t fontasset;            
            uint16_t backcolor;
            uint16_t forecolor;
            
            uint16_t align: 4; 
            uint16_t fill: 1; 
            uint16_t encoding: 1;          
            
            ui_ext_property_t* extension;
        }uiText;

        // share common property 
        struct 
        {
            uint16_t imagelist;
            uint16_t imageidx; 
            uint16_t maskcolor;            
        }uiPicture;
#endif 

    };
}ui_widgets_type_t;

// widget max length 40bytes 

// 定义touch控件的属性
// 一般来说推荐使用touch来检查触摸位置
// 原控件中也可以检测，但不推荐
typedef struct 
{
    uint16_t type; 
    int16_t x;
    int16_t y;
    uint16_t w;
    uint16_t h; 

    uint16_t tag:     8; // tag，用来区别控件触摸事件
    uint16_t visible: 1; // 0表示控件不可见，1表示可见
    uint16_t border:  1; // 是否绘制边框，目前仅支持progressbar 
    uint16_t touchable:   1; // 当允许触摸时，同一组控件需要定义不同的tag，用来区分哪个触摸生效的对象
    uint16_t overlay:     1; // 使用图片控件时，此属性为0，图片将覆盖； 1表示叠加（叠加时需要指定透明颜色 ）

}ui_widgets_touch_t;

#if defined (__CC_ARM)
#pragma pop 
#endif 

#define uiTouch(X,Y,W,H,TAG) {\
    .type = UI_WIDGET_TYPE_TOUCH,\
    .x = X, .y = Y, .w = W, .h = H,\
    .touchable = 1,\
    .tag = TAG,\
}

// without data source 
#define uiAimate(IMAGELIST,CNT,X,Y,W,H) {\
    .type = UI_WIDGET_TYPE_ANIMATE,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 0,\
    .uiAnimation.imagelist = IMAGELIST,\
    .uiAnimation.counts = CNT,\
}

#define uiAimateOverlay(IMAGELIST,CNT,X,Y,W,H,MASKCOLOR) {\
    .type = UI_WIDGET_TYPE_ANIMATE,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiAnimation.imagelist = IMAGELIST,\
    .uiAnimation.counts = CNT,\
    .uiAnimation.maskcolor = MASKCOLOR,\
}

/*
    定义一个画布控件，指定在（X，Y)位置上绘制一个颜色为（COLOR)，宽W高H的实心矩形
参数说明：
    X   -控件起始坐标x
    Y   -控件起始坐标y
    W   -控件宽度
    H   -控件高度
    COLOR - 控件颜色 
*/
#define uiCanvas(X,Y,W,H,COLOR) {\
    .type = UI_WIDGET_TYPE_CANVAS,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiCanvas.color = COLOR,\
}

#define uiContainer(X,Y,W,H,CNT) {\
    .type = UI_WIDGET_TYPE_CONTAINER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiContainer.sub_widget_cnt = CNT,\
}

#define uiContainerClick(X,Y,W,H,CNT,TAG) {\
    .type = UI_WIDGET_TYPE_CONTAINER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .touchable = 1,\
    .tag = TAG,\
    .uiContainer.sub_widget_cnt = CNT,\
    .uiContainer.delta_x = 0,\
    .uiContainer.delta_y = 0,\
}

#define uiCirclebar(X,Y,W,H,COLOR,RADIUS,THICKNESS) {\
    .type = UI_WIDGET_TYPE_CIRCLEBAR,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiCirclebar.color = COLOR, \
    .uiCirclebar.radius = RADIUS, \
    .uiCirclebar.thickness = THICKNESS, \
}

#define uiCirclebarWithAngle(X,Y,W,H,COLOR,RADIUS,THICKNESS,AS,AE) {\
    .type = UI_WIDGET_TYPE_CIRCLEBAR,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiCirclebar.color = COLOR, \
    .uiCirclebar.radius = RADIUS, \
    .uiCirclebar.thickness = THICKNESS, \
    .uiCirclebar.angles = AS,\
    .uiCirclebar.anglee = AE,\
}

#define uiColorReplacer(X,Y,W,H,SRCCOLOR,DSTCOLOR) {\
    .type = UI_WIDGET_TYPE_COLORREPLACER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiColorReplacer.srcColor = SRCCOLOR,\
    .uiColorReplacer.dstColor = DSTCOLOR,\
}

#define uiDigital(IMAGELIST,X,Y,W,H ) {\
    .type = UI_WIDGET_TYPE_DIGITAL,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 0,\
    .uiDigital.imagelist = IMAGELIST,\
}

#define uiDigitalOverlay(IMAGELIST,X,Y,W,H, MASKCOLOR ) {\
    .type = UI_WIDGET_TYPE_DIGITAL,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiDigital.imagelist = IMAGELIST,\
    .uiDigital.maskcolor = MASKCOLOR, \
}

#define uiDigitallist(IMAGELIST,X,Y,W,H,FORMAT) {\
    .type = UI_WIDGET_TYPE_DIGITALLIST,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 0,\
    .uiDigitallist.imagelist = IMAGELIST,\
    .uiDigitallist.format = FORMAT,\
}

#define uiDigitallistOverlay(IMAGELIST,X,Y,W,H,FORMAT,MASKCOLOR) {\
    .type = UI_WIDGET_TYPE_DIGITALLIST,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiDigitallist.imagelist = IMAGELIST,\
    .uiDigitallist.maskcolor = MASKCOLOR,\
    .uiDigitallist.format = FORMAT,\
}

/*
    X   - 控件起始坐标x
    Y   - 控件起始坐标y
    W   - 控件宽度
    Y   - 控件高度
    BC  - 控件背景颜色 
    FC  - 控件前景颜色
    ALIGN - 文本对齐方式
    FILL - 文本填充方式
    ENCODING - 文本编码方式
    FA  - 字库资源指定
    TEXT - 文本地址
    LEN - 文本长度
*/
#define uiLabel(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA, TEXT, LEN ) {\
    .type = UI_WIDGET_TYPE_LABEL,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiLabel.backcolor = BC, \
    .uiLabel.forecolor = FC, \
    .uiLabel.align = ALIGN, \
    .uiLabel.fill = FILL, \
    .uiLabel.encoding = ENCODING, \
    .uiLabel.fontasset = FA, \
    .uiLabel.content = (void*)TEXT,\
    .uiLabel.len = LEN,\
}

#define uiNumber(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA,FORMAT) {\
    .type = UI_WIDGET_TYPE_NUMBER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiNumber.backcolor = BC,\
    .uiNumber.forecolor = FC,\
    .uiNumber.align = ALIGN,\
    .uiNumber.fill = FILL,\
    .uiNumber.encoding = ENCODING,\
    .uiNumber.fontasset = FA,\
    .uiNumber.format = FORMAT,\
    .uiNumber.content = NULL,\
    .uiNumber.len = 0,\
}

#define uiNumberWithBuffer(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA,FORMAT,TEXT,MAXLEN) {\
    .type = UI_WIDGET_TYPE_NUMBER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiNumber.backcolor = BC,\
    .uiNumber.forecolor = FC,\
    .uiNumber.align = ALIGN,\
    .uiNumber.fill = FILL,\
    .uiNumber.encoding = ENCODING,\
    .uiNumber.fontasset = FA,\
    .uiNumber.format = FORMAT,\
    .uiNumber.content = (void*)TEXT,\
    .uiNumber.maxlen = MAXLEN,\
}

#define uiNumberlist(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA,FORMAT) {\
    .type = UI_WIDGET_TYPE_NUMBERLIST,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiNumberlist.backcolor = BC,\
    .uiNumberlist.forecolor = FC,\
    .uiNumberlist.align = ALIGN,\
    .uiNumberlist.fill = FILL,\
    .uiNumberlist.encoding = ENCODING,\
    .uiNumberlist.fontasset = FA,\
    .uiNumberlist.format = FORMAT,\
    .uiNumberlist.content = NULL,\
    .uiNumberlist.len = 0,\
}

#define uiNumberlistWithBuffer(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA,FORMAT,TEXT,MAXLEN) {\
    .type = UI_WIDGET_TYPE_NUMBERLIST,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiNumberlist.backcolor = BC,\
    .uiNumberlist.forecolor = FC,\
    .uiNumberlist.align = ALIGN,\
    .uiNumberlist.fill = FILL,\
    .uiNumberlist.encoding = ENCODING,\
    .uiNumberlist.fontasset = FA,\
    .uiNumberlist.format = FORMAT,\
    .uiNumberlist.content = (void*)TEXT,\
    .uiNumberlist.maxlen = MAXLEN,\
}

#define uiPicker(X,Y,W,H,FC,ALIGN,ENCODING,FA,PITCH) {\
    .type = UI_WIDGET_TYPE_PICKER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiPicker.forecolor = FC,\
    .uiPicker.align = ALIGN,\
    .uiPicker.fill = 0,\
    .uiPicker.encoding = ENCODING,\
    .uiPicker.fontasset = FA,\
    .uiPicker.pitch = PITCH,\
}

#define uiPictureBox(IMAGELIST,IDX,X,Y,W,H) {\
    .type = UI_WIDGET_TYPE_PICTUREBOX,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 0,\
    .uiPicturebox.imagelist = IMAGELIST,\
    .uiPicturebox.idx = IDX,\
}

#define uiPictureBoxOverlay(IMAGELIST,IDX,X,Y,W,H,MASKCOLOR) {\
    .type = UI_WIDGET_TYPE_PICTUREBOX,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiPicturebox.imagelist = IMAGELIST,\
    .uiPicturebox.idx = IDX,\
    .uiPicturebox.maskcolor = MASKCOLOR,\
}

#define uiPointer(IMAGELIST,IDX,X,Y,W,H,PX,PY,MASKCOLOR) {\
    .type = UI_WIDGET_TYPE_POINTER,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiPointer.imagelist = IMAGELIST,\
    .uiPointer.idx = IDX,\
    .uiPointer.maskcolor = MASKCOLOR,\
    .uiPointer.pivot_x = PX,\
    .uiPointer.pivot_y = PY,\
    .uiPointer.angle = 0,\
}

#define uiProgressbar(X,Y,W,H,BC,FC) {\
    .type = UI_WIDGET_TYPE_PROGRESSBAR,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiProgressbar.backcolor = BC,\
    .uiProgressbar.forecolor = FC,\
}

#define uiQrcode(X,Y,W,H,BC,FC,MATRIX) {\
    .type = UI_WIDGET_TYPE_QRCODE,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiQrcode.backcolor = BC,\
    .uiQrcode.forecolor = FC,\
    .uiQrcode.matrix = (uint8_t*)MATRIX,\
}

#define uiSwitch(IMAGELIST,IDXON,IDXOFF,X,Y,W,H) {\
    .type = UI_WIDGET_TYPE_SWITCH,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 0,\
    .uiSwitch.imagelist = IMAGELIST,\
    .uiSwitch.idxon = IDXON,\
    .uiSwitch.idxoff = IDXOFF,\
    .uiSwitch.idx = IDXOFF,\
}

#define uiSwitchOverlay(IMAGELIST,IDXON,IDXOFF,X,Y,W,H,MASKCOLOR) {\
    .type = UI_WIDGET_TYPE_SWITCH,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .overlay = 1,\
    .uiSwitch.imagelist = IMAGELIST,\
    .uiSwitch.idxon = IDXON,\
    .uiSwitch.idxoff = IDXOFF,\
    .uiSwitch.idx = IDXOFF,\
    .uiSwitch.maskcolor = MASKCOLOR,\
}

#define uiTextbox(X,Y,W,H,BC,FC,ALIGN,FILL,ENCODING,FA ) {\
    .type = UI_WIDGET_TYPE_TEXTBOX,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiTextbox.backcolor = BC,\
    .uiTextbox.forecolor = FC,\
    .uiTextbox.align = ALIGN,\
    .uiTextbox.fill = FILL,\
    .uiTextbox.encoding = ENCODING,\
    .uiTextbox.fontasset = FA,\
    .uiTextbox.content = NULL,\
    .uiTextbox.len = 0,\
}

// only support UNICODE 
#define uiTextpage(X,Y,W,H,BC,FC,ALIGN,FILL,FA ) {\
    .type = UI_WIDGET_TYPE_TEXTPAGE,\
    .x = X, .y = Y, .w = W, .h = H,\
    .visible = 1,\
    .uiTextpage.backcolor = BC,\
    .uiTextpage.forecolor = FC,\
    .uiTextpage.align = ALIGN,\
    .uiTextpage.fill = FILL,\
    .uiTextpage.encoding = 1,\
    .uiTextpage.fontasset = FA,\
}


#endif 
